﻿using System;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;


namespace ASPNETVN.PORTAL.Modules.GUIDE.Components
{
    public partial class Article
    {
        public static DataSet SelectArticles_ByModuleID(Guid moduleID, int categoryID, int guiderID, string title)
        {
            const string spName = "p_GUIDE_Article_SelectArticles_ByModuleID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@CategoryID", SqlDbType.Int, categoryID);
            db.AddInParameter(dbCommand, "@GuiderID", SqlDbType.Int, guiderID);
            db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, title);

            return db.ExecuteDataSet(dbCommand);
        }

        public static int GetArticleCount(Guid moduleID, int categoryID, int guiderID)
        {
            const string spName = "[dbo].[p_GUIDE_Article_Count]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();

            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@CategoryID", SqlDbType.Int, categoryID);
            db.AddInParameter(dbCommand, "@GuiderID", SqlDbType.Int, guiderID);

            return Convert.ToInt32(db.ExecuteScalar(dbCommand));
        }

        public static DataSet GetArticle_ByArticleID(int articleID)
        {
            string spName = "[dbo].[p_GUIDE_Article_SelectArticles_ByArticleID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ArticleID", SqlDbType.Int, articleID);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
